package com.example.studentportrait.controller.admin.Assessment;


import com.example.studentportrait.domain.ResponseResult;
import com.example.studentportrait.domain.dto.ListAssessmentQuestionDto;
import com.example.studentportrait.domain.entity.AssessmentQuestion;
import com.example.studentportrait.service.AssessmentQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/assessmentQuestion")
public class AssessmentQuestionController {
    @Autowired
    private AssessmentQuestionService assessmentQuestionService;

    /**
     * 获取题库列表
     * @param page
     * @param size
     * @param listAssessmentQuestionDto
     * @return
     */
    @GetMapping("/assessmentQuestionList")
    public ResponseResult assessmentQuestionList( @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size, @RequestBody ListAssessmentQuestionDto listAssessmentQuestionDto) {
        return assessmentQuestionService.assessmentQuestionlist(page,size,listAssessmentQuestionDto);
    }

    /**
     * 增加题目
     * @param assessmentQuestion
     * @return
     */
    @PostMapping("addAssessmentQuestion")
    public ResponseResult addAssessmentQuestion(@RequestBody AssessmentQuestion assessmentQuestion) {
        if (assessmentQuestion == null) {
            return ResponseResult.errorResult(500,"出现错误");
        }
        assessmentQuestion.setCreateTime(new Date());
        assessmentQuestion.setUpdateTime(new Date());
        System.out.println(assessmentQuestion);
        return assessmentQuestionService.addAssessmentQuestion(assessmentQuestion);
    }

    /**
     * 更新题目
     * @param assessmentQuestion
     * @return
     */
    @PutMapping("updateAssessmentQuestion")
    public ResponseResult<AssessmentQuestion> updateAssessmentQuestion(@RequestBody AssessmentQuestion assessmentQuestion){
        return assessmentQuestionService.updateAssessmentQuestion(assessmentQuestion);
    }

    /**
     * 删除题目
     * @param id
     * @return
     */
    @DeleteMapping("deleteAssessmentQuestion")
    public ResponseResult deleteAssessmentQuestion(@RequestParam("id") Integer id) {
        return assessmentQuestionService.deleteAssessmentQuestion(id);
    }

    /**
     * 批量删除题目
     * @param ids
     * @return
     */
    @DeleteMapping("deleteAssessmentQuestions")
    public ResponseResult deleteAssessmentQuestions(@RequestBody List<Integer> ids){
        return assessmentQuestionService.deleteAssessmentQuestions(ids);
    }

    /**
     *Excel批量导入
     * @param file
     * @return
     */
    @PostMapping("insertAssessmentQuestionListByExcel")
    public ResponseResult insertMajorAssessmentListByExcel(@RequestParam(value = "file", required = true) MultipartFile file) {
//        String authorization = request.getHeader("Authorization");
//        Integer userId = JwtUtils.parseTokenGetUserId(authorization);
        return assessmentQuestionService.insertAssessmentQuestionListByExcel(file);
    }
}
